using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the AspnetPath class.
	/// </summary>
	[Serializable]
	public partial class AspnetPathCollection : ActiveList<AspnetPath, AspnetPathCollection> 
	{	   
		public AspnetPathCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the aspnet_Paths table.
	/// </summary>
	[Serializable]
	public partial class AspnetPath : ActiveRecord<AspnetPath>
	{
		#region .ctors and Default Settings
		
		public AspnetPath()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AspnetPath(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AspnetPath(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AspnetPath(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("aspnet_Paths", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarApplicationId = new TableSchema.TableColumn(schema);
				colvarApplicationId.ColumnName = "ApplicationId";
				colvarApplicationId.DataType = DbType.Guid;
				colvarApplicationId.MaxLength = 0;
				colvarApplicationId.AutoIncrement = false;
				colvarApplicationId.IsNullable = false;
				colvarApplicationId.IsPrimaryKey = false;
				colvarApplicationId.IsForeignKey = true;
				colvarApplicationId.IsReadOnly = false;
				colvarApplicationId.DefaultSetting = @"";
				
					colvarApplicationId.ForeignKeyTableName = "aspnet_Applications";
				schema.Columns.Add(colvarApplicationId);
				
				TableSchema.TableColumn colvarPathId = new TableSchema.TableColumn(schema);
				colvarPathId.ColumnName = "PathId";
				colvarPathId.DataType = DbType.Guid;
				colvarPathId.MaxLength = 0;
				colvarPathId.AutoIncrement = false;
				colvarPathId.IsNullable = false;
				colvarPathId.IsPrimaryKey = true;
				colvarPathId.IsForeignKey = false;
				colvarPathId.IsReadOnly = false;
				
						colvarPathId.DefaultSetting = @"(newid())";
				colvarPathId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPathId);
				
				TableSchema.TableColumn colvarPath = new TableSchema.TableColumn(schema);
				colvarPath.ColumnName = "Path";
				colvarPath.DataType = DbType.String;
				colvarPath.MaxLength = 256;
				colvarPath.AutoIncrement = false;
				colvarPath.IsNullable = false;
				colvarPath.IsPrimaryKey = false;
				colvarPath.IsForeignKey = false;
				colvarPath.IsReadOnly = false;
				colvarPath.DefaultSetting = @"";
				colvarPath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPath);
				
				TableSchema.TableColumn colvarLoweredPath = new TableSchema.TableColumn(schema);
				colvarLoweredPath.ColumnName = "LoweredPath";
				colvarLoweredPath.DataType = DbType.String;
				colvarLoweredPath.MaxLength = 256;
				colvarLoweredPath.AutoIncrement = false;
				colvarLoweredPath.IsNullable = false;
				colvarLoweredPath.IsPrimaryKey = false;
				colvarLoweredPath.IsForeignKey = false;
				colvarLoweredPath.IsReadOnly = false;
				colvarLoweredPath.DefaultSetting = @"";
				colvarLoweredPath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLoweredPath);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("aspnet_Paths",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ApplicationId")]
		public Guid ApplicationId 
		{
			get { return GetColumnValue<Guid>("ApplicationId"); }

			set { SetColumnValue("ApplicationId", value); }

		}

		  
		[XmlAttribute("PathId")]
		public Guid PathId 
		{
			get { return GetColumnValue<Guid>("PathId"); }

			set { SetColumnValue("PathId", value); }

		}

		  
		[XmlAttribute("Path")]
		public string Path 
		{
			get { return GetColumnValue<string>("Path"); }

			set { SetColumnValue("Path", value); }

		}

		  
		[XmlAttribute("LoweredPath")]
		public string LoweredPath 
		{
			get { return GetColumnValue<string>("LoweredPath"); }

			set { SetColumnValue("LoweredPath", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public LMSData.AspnetPersonalizationAllUserCollection AspnetPersonalizationAllUsers()
		{
			return new LMSData.AspnetPersonalizationAllUserCollection().Where(AspnetPersonalizationAllUser.Columns.PathId, PathId).Load();
		}

		public LMSData.AspnetPersonalizationPerUserCollection AspnetPersonalizationPerUserRecords()
		{
			return new LMSData.AspnetPersonalizationPerUserCollection().Where(AspnetPersonalizationPerUser.Columns.PathId, PathId).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a AspnetApplication ActiveRecord object related to this AspnetPath
		/// 
		/// </summary>
		public LMSData.AspnetApplication AspnetApplication
		{
			get { return LMSData.AspnetApplication.FetchByID(this.ApplicationId); }

			set { SetColumnValue("ApplicationId", value.ApplicationId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varApplicationId,Guid varPathId,string varPath,string varLoweredPath)
		{
			AspnetPath item = new AspnetPath();
			
			item.ApplicationId = varApplicationId;
			
			item.PathId = varPathId;
			
			item.Path = varPath;
			
			item.LoweredPath = varLoweredPath;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varApplicationId,Guid varPathId,string varPath,string varLoweredPath)
		{
			AspnetPath item = new AspnetPath();
			
				item.ApplicationId = varApplicationId;
				
				item.PathId = varPathId;
				
				item.Path = varPath;
				
				item.LoweredPath = varLoweredPath;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ApplicationId = @"ApplicationId";
			 public static string PathId = @"PathId";
			 public static string Path = @"Path";
			 public static string LoweredPath = @"LoweredPath";
						
		}

		#endregion
	}

}

